﻿using System.Globalization;
using System.Windows.Data;

namespace VideoTools.Converters
{
    public class RemoveListEmptyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return value;
            }
            if(value is IList<string> vals)
            {
                string[] strings = vals.ToArray<string>();
                foreach (string s in strings)
                {
                    if (s == null || s.Length == 0 || s.Trim().Length == 0)
                    {
                        vals.Remove(s);
                    }
                }
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
